package com.waitingresult.designpattern.behavioral.strategy.service;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class UserIdEntityManager {
    /**
     * 存放所有策略实现 的容器
     */
    private Map<Long, UserIdEntityService> userIdEntityServiceMap = new ConcurrentHashMap<>();

    /**
     * 通过构造方法来注入Map
     *
     * @param userIdEntityServiceList
     */
    public UserIdEntityManager(List<UserIdEntityService> userIdEntityServiceList) {
        for (UserIdEntityService userIdEntityService : userIdEntityServiceList) {
            userIdEntityServiceMap.put(userIdEntityService.instanceType(), userIdEntityService);
        }
    }

    /**
     * 统一策略入口
     *
     * @param idType
     * @return
     */
    public UserIdEntityService getUserIdEntityService(Long idType) {
        return userIdEntityServiceMap.get(idType);
    }
}
